import request from '@/config/axios'
import { healthDataType } from '@/views/ParkHealth/types/health'

// 卫生信息列表
interface WhereType {
  name: { $regex: string; $options: 'i' }
}

export const healthMapGet = () => {
  return request.get({ url: '/1.1/classes/Health' })
}

export const parkHealthGet = (
  page: number = 1,
  size: number = 10,
  condition?: { name: string }
) => {
  const skip = (page - 1) * size
  const where: WhereType = {} as WhereType
  //携带岗位名称
  if (condition && condition.name) {
    where.name = { $regex: condition.name, $options: 'i' }
    // console.log("adaddasd");
  }

  const query = JSON.stringify(where)
  return request.get({
    url: `/1.1/classes/Health?where=${query}&limit=${size}&count=${1}&skip=${skip}`
    // params: {
    //     limit: size,
    //     count: 1, //开启对象计数（数据表总条数）
    //     skip,
    // }
  })
}

// 新增
export const parkHealthPost = (data) => {
  return request.post({ url: '/1.1/classes/Health', data })
}

// 删除
export const parkHealthDel = (id: string) => {
  // 发起delete请求
  return request.delete({ url: `/1.1/classes/Health/${id}` })
}

// 新增编辑角色
export const parkHealthPut = (id: string, data: Omit<healthDataType, 'objectId'>) => {
  // 发起put请求
  return request.put({ url: `/1.1/classes/Health/${id}`, data })
}
